//
//  LabelView.m
//  CarLifes
//
//  Created by yu on 2017/6/30.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "LabelView.h"

@implementation LabelView

- (instancetype)init {
    if (self = [super init]) {
        
        if (@available(iOS 13.0, *)) {
            self.backgroundColor = UIColor.secondarySystemGroupedBackgroundColor;
        } else {
            self.backgroundColor = UIColor.whiteColor;
        }
        
        UIView *lineView = [[UIView alloc] init];
        if (@available(iOS 13.0, *)) {
            lineView.backgroundColor = UIColor.separatorColor;
        } else {
            lineView.backgroundColor = kTextGrayColor;
        }
        [self addSubview:lineView];
        
        lineView.sd_layout
        .leftEqualToView(self)
        .rightEqualToView(self)
        .centerYEqualToView(self)
        .heightIs(20);
        
        
        NSArray *titleLabels = @[@"设备号",@"告警类型",@"告警时间"];
        NSMutableArray *temp = [NSMutableArray new];
        
        for (int i = 0; i < titleLabels.count; i++) {
            UILabel *label = [[UILabel alloc] init];
            [self addSubview:label];
            
            //label.backgroundColor = [UIColor whiteColor];
            if (@available(iOS 13.0, *)) {
                
                label.backgroundColor = UIColor.secondarySystemGroupedBackgroundColor;
                
                
                UIColor *textColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                    if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                        return kTextBlackColor;
                    } else {
                        return UIColor.secondaryLabelColor;
                    }
                }];
                
                label.textColor = textColor;
            } else {
                label.backgroundColor = UIColor.whiteColor;
                label.textColor = kTextBlackColor;
            }
            label.font = SYSTEM_FONT(15);
            label.text = titleLabels[i];
            label.textAlignment = NSTextAlignmentCenter;
            label.sd_layout.heightIs(40);
            [temp addObject:label];
        }
        
        [self setupAutoWidthFlowItems:[temp copy] withPerRowItemsCount:3 verticalMargin:0 horizontalMargin:1 verticalEdgeInset:0 horizontalEdgeInset:0];
        
    }
    return self;
}

@end
